<template>
<el-drawer :title="!dataForm.id ? '新建' : '编辑'" :visible.sync="visible"
           :wrapperClosable="false" size="1000px" append-to-body
           class="JNPF-common-drawer">
<div class="JNPF-flex-main">
<div class="dynamicForm ">
<el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="100px" label-position="right" >
    <template v-if="!loading">
        <el-col :span="24">
        <el-row :gutter="15">
            <el-col :span="6"  >
                <el-form-item  label="通知单编号"
 prop="notificationId" >
                    <el-input   v-model="dataForm.notificationId"
 placeholder="请输入"  clearable  :style='{"width":"100%"}'>

                </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6"  >
                <el-form-item  label="客户名称"
 prop="customerName" >
                    <el-input   v-model="dataForm.customerName"
 placeholder="请输入"  clearable  :style='{"width":"100%"}'>

                </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6"  >
                <el-form-item  label="合同编号"
 prop="contractNo" >
                    <el-input   v-model="dataForm.contractNo"
 placeholder="请输入"  clearable  :style='{"width":"100%"}'>

                </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6"  >
                <el-form-item  label="资产名称"
 prop="leaseSpace" >
                    <el-input   v-model="dataForm.leaseSpace"
 placeholder="请输入"  clearable  :style='{"width":"100%"}'>

                </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6"  >
                <el-form-item  label="催款本金"
 prop="collectionPrincipal" >
                    <el-input   v-model="dataForm.collectionPrincipal"
 placeholder="请输入"  clearable  :style='{"width":"100%"}'>

                </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6"  >
                <el-form-item  label="催款滞纳金"
 prop="collectionLateFee" >
                    <el-input   v-model="dataForm.collectionLateFee"
 placeholder="请输入"  clearable  :style='{"width":"100%"}'>

                </el-input>
                </el-form-item>
            </el-col>
            <el-col :span="6"  >
                <el-form-item  label="创建时间"
 prop="creatortime" >
                    <el-input   v-model="dataForm.creatortime"
 placeholder="请输入"  clearable  :style='{"width":"100%"}'>

                </el-input>
                </el-form-item>
            </el-col>
        </el-row>
        </el-col>
    </template>
</el-form>
    <SelectDialog v-if="selectDialogVisible" :config="currTableConf" :formData="dataForm"
              ref="selectDialog" @select="addForSelect" @close="selectDialogVisible=false"/>
    </div>
        <div class="drawer-footer">
            <el-button @click="visible = false"> 取 消</el-button>
            <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> 确 定</el-button>
        </div>
    </div>
    </el-drawer>
</template>
<script>
    import request from '@/utils/request'
    import { getDataInterfaceRes } from '@/api/systemData/dataInterface'
    import { getDictionaryDataSelector } from '@/api/systemData/dictionary'

    export default {
        components: {},
        props: [],
        data() {
            return {
                visible: false,
                loading: false,
                btnLoading: false,
                selectDialogVisible: false,
                currTableConf:{},
                addTableConf:{
            },
                tableRows:{
                },
            currVmodel:"",
            dataForm: {
                                    notificationId : '',
                                    customerName : '',
                                    contractNo : '',
                                    leaseSpace : '',
                                    collectionPrincipal : '',
                                    collectionLateFee : '',
                                    creatortime : '',
            },
            rules:
            {



            },

        }
        },
        computed: {},
        watch: {},
        created() {
        },
        mounted() {},
        methods: {
            clearData(){
                               this.dataForm.notificationId = '';
                               this.dataForm.customerName = '';
                               this.dataForm.contractNo = '';
                               this.dataForm.leaseSpace = '';
                               this.dataForm.collectionPrincipal = '';
                               this.dataForm.collectionLateFee = '';
                               this.dataForm.creatortime = '';
            },
            init(id) {
                this.dataForm.id = id || 0;
                this.visible = true;
                this.$nextTick(() => {
                    this.$refs['elForm'].resetFields();
                    if(this.dataForm.id){
                        this.loading = true
                        request({
                            url: '/api/example/ZcglCwDebtCollectionLog/'+this.dataForm.id,
                            method: 'get'
                        }).then(res => {
                            this.dataInfo(res.data)
                            this.loading = false
                        });
                    }else{
                       this.clearData()
                    }
                });
                this.$store.commit('generator/UPDATE_RELATION_DATA', {})
            },
            // 表单提交
            dataFormSubmit() {
                this.$refs['elForm'].validate((valid) => {
                    if (valid) {
                            this.request()
                    }
                })
            },
            request() {
                this.btnLoading = true
                let _data =this.dataList()
                if (!this.dataForm.id) {
                    request({
                        url: '/api/example/ZcglCwDebtCollectionLog',
                        method: 'post',
                        data: _data
                    }).then((res) => {
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () => {
                                this.visible = false
                                this.btnLoading = false
                                this.$emit('refresh', true)
                            }
                        })
                    }).catch(()=>{  this.btnLoading = false  })
                }else{
                    request({
                        url: '/api/example/ZcglCwDebtCollectionLog/'+this.dataForm.id,
                        method: 'PUT',
                        data: _data
                    }).then((res) => {
                        this.$message({
                            message: res.msg,
                            type: 'success',
                            duration: 1000,
                            onClose: () => {
                                this.visible = false
                                this.btnLoading = false
                                this.$emit('refresh', true)
                            }
                        })
                    }).catch(()=>{  this.btnLoading = false  })
                }
            },
            openSelectDialog(key) {
                this.currTableConf=this.addTableConf[key]
                this.currVmodel=key
                this.selectDialogVisible = true
                this.$nextTick(() => {
                    this.$refs.selectDialog.init()
                })
            },
            addForSelect(data) {
                for (let i = 0; i < data.length; i++) {
                    let item={...this.tableRows[this.currVmodel],...data[i]}
                    this.dataForm[this.currVmodel].push(item)
                }
            },
            dataList(){
                var _data = JSON.parse(JSON.stringify(this.dataForm));
                return _data;
            },
            dataInfo(dataAll){
                let _dataAll =dataAll
                this.dataForm = _dataAll
            },
        },
    }

</script>
